package com.kaiwukj.android.ufamily.mvp.ui.page.dynamic.shield;

import androidx.annotation.NonNull;

import com.kaiwukj.android.mcas.mvp.BasePresenter;
import com.kaiwukj.android.mcas.utils.RxLifecycleUtils;
import com.kaiwukj.android.ufamily.mvp.http.callback.ApiCallBack;
import com.kaiwukj.android.ufamily.mvp.http.entity.base.ListResp;
import com.kaiwukj.android.ufamily.mvp.http.entity.result.ShieldResult;
import com.kaiwukj.android.ufamily.mvp.http.utils.RxUtils;
import com.kaiwukj.android.ufamily.mvp.ui.page.dynamic.DynamicContract;

import javax.inject.Inject;

import me.jessyan.rxerrorhandler.core.RxErrorHandler;

public class ShieldPresenter extends BasePresenter<DynamicContract.Model, DynamicContract.ReportView> {

    public static final int SHIELD = 1;

    @Inject
    RxErrorHandler mErrorHandler;

    @Inject
    public ShieldPresenter(DynamicContract.Model model, DynamicContract.ReportView view) {
        super(model, view);
    }


    public void fetchShieldList(int page, int pageSize) {
        mModel.fetchShieldList(page, pageSize)
                .compose(RxUtils.schedulerHelper())
                .compose(RxLifecycleUtils.bindToLifecycle(mRootView))
                .subscribe(new ApiCallBack<ListResp<ShieldResult>>(mErrorHandler, mRootView) {
                    @Override
                    public void onSuccess(@NonNull ListResp<ShieldResult> result) {
                        mRootView.onFetchShieldList(result.getList());
                    }
                });
    }

    public void shieldCancel(int resId) {
        mModel.shield(resId, false, true)
                .doOnSubscribe(act -> mRootView.showLoading("正在处理..."))
                .doFinally(() -> mRootView.hideLoading())
                .compose(RxUtils.schedulerHelper())
                .compose(RxLifecycleUtils.bindToLifecycle(mRootView))
                .subscribe(new ApiCallBack<Integer>(mErrorHandler, mRootView, SHIELD) {
                    @Override
                    public void onSuccess(@NonNull Integer result) {

                    }
                });
    }


}
